package com.chuan.thinkingjava.interview.look.cas;

import java.util.concurrent.atomic.AtomicInteger;

public class TestSys {

    private AtomicInteger atomicInteger = new AtomicInteger(0);

    private synchronized void sum() {
//        atomicInteger.set(atomicInteger.get() + 1);
        atomicInteger.incrementAndGet();
    }


    public static void main(String[] args) throws InterruptedException {
        TestSys testSys = new TestSys();
        for (int j = 0; j < 2; j++) {
            new Thread(() -> {
                for (int i = 0; i < 10000; i++) {
                    testSys.sum();
                }
            }).start();
        }
        Thread.sleep(1000L);
        System.out.println(testSys.atomicInteger);
    }
}
